package com.cardbaobao.cardbabyclient.ui.adapter;

import android.content.Context;
import android.widget.ImageView;
import android.widget.RelativeLayout.LayoutParams;

import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.ui.adapter.base.CommonAdapter;
import com.cardbaobao.cardbabyclient.ui.adapter.base.ViewHolder;
import com.cardbaobao.cardbabyclient.utils.DensityUtil;
import com.cardbaobao.cardbabyclient.utils.ScreenUtil;

import java.util.List;

/**
 * 显示相册图片适配器
 *
 * @author zad
 */
public class GetPhotosAdapter extends CommonAdapter<String> {
    /**
     * 文件夹路径
     */
    private String mDirPath;

    private Context context;
    /**
     * item高度
     */
    private int itemHeight;

    private LayoutParams params;

    public GetPhotosAdapter(Context context, List<String> mDatas, int itemLayoutId, String dirPath) {
        super(context, mDatas, itemLayoutId);
        this.mDirPath = dirPath;
        this.context = context;
        this.itemHeight = (ScreenUtil.getScreenWidth(context) - 4 * DensityUtil.dp2px(context, 3)) / 3;
    }

    @Override
    public void convert(final ViewHolder helper, final String item, final int position) {
        final ImageView mImageView = helper.getView(R.id.id_item_image);//要显示的图片
        if (params == null) {
            params = (LayoutParams) mImageView.getLayoutParams();
            params.height = itemHeight;
        }
        mImageView.setLayoutParams(params);//设置图片显示宽高

        if (position == 0) {
            helper.setImageResource(R.id.id_item_image, R.drawable.ic_take_photo);
            helper.setImageByUrl(R.id.id_item_image, "-1");
        } else {
            helper.setImageResource(R.id.id_item_image, R.drawable.shape_photos_bg);//设置默认显示图片
            //加载本地相册设置图片
            helper.setImageByUrl(R.id.id_item_image, mDirPath + "/" + item);
        }
        mImageView.setColorFilter(null);
    }
}
